package emulator.hardware.nmos6502.commands;

import emulator.EmulatorException;
import emulator.hardware.nmos6502.Command;
import emulator.hardware.nmos6502.CommandSet;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.Operand;
import emulator.hardware.nmos6502.operands.NoOperand;
import emulator.hardware.nmos6502.stack.StackData;

public class BRK implements Command {

	@Override
	public void execute(Cpu6502 cpu, Operand operand) throws EmulatorException {
		
		cpu.pushAddress(cpu.getPC()+1, StackData.SOURCE_BREAK);
		cpu.setPC(cpu.readWord(Cpu6502.IRQ_VECTOR));
		
		Flags6502 flags = cpu.getFlags();
		flags.setBreak(true);
		cpu.pushByte((int) flags.getNumber(), StackData.DATA_FLAGS);
	}

	@Override
	public String getName() {
		return "BRK";
	}

	@Override
	public void register(CommandSet cset) {
		cset.defineCommand(0x00, this, new NoOperand(), 7);
	}

}
